package com.huxiu.holder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huxiu.CommentActivity;
import com.huxiu.DetailActivity;
import com.huxiu.R;
import com.huxiu.net.model.ReamarkCommentItem;
import com.huxiu.utils.Constants;
import com.huxiu.utils.Settings;
import com.huxiu.utils.Utils;
import com.huxiu.view.RefreshListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.lang.ref.WeakReference;


public class RemarkCommentHolder implements OnClickListener {


    @ViewInject(R.id.container)
    private LinearLayout container;

    @ViewInject(R.id.airtlecontent)
    private TextView airtlecontent;


    @ViewInject(R.id.content)
    private TextView content;

    @ViewInject(R.id.time)
    private TextView time;

    @ViewInject(R.id.look_airtle)
    private TextView look_airtle;


    private static Activity mContext;
    private int position = -1;
    private RefreshListView lv_tabdetail_list;
    private static WeakReference<BaseAdapter> mAdapter;

    public void setAdapter(BaseAdapter adapter) {
        mAdapter = new WeakReference<>(adapter);
    }

    public RemarkCommentHolder(View view, Context context) {
        ViewUtils.inject(this, view);
        mContext = (Activity) context;
        look_airtle.setOnClickListener(this);
        container.setOnClickListener(this);
    }

    private ReamarkCommentItem mItem;

    public void bindItem(ReamarkCommentItem item) {
        mItem = item;
        airtlecontent.setText(mItem.origin_comment.message);
        content.setText(mItem.comment);
        time.setText(Utils.getDateString(mItem.dateline));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.look_airtle:
                if (!Settings.isLoggedIn()) {
                    Utils.showToast("登录后才能点赞");
                    Utils.askLogIn(mContext);
                    return;
                }
                Intent intent = new Intent(mContext, DetailActivity.class);
                intent.putExtra(Constants.COMMENT_ITEM_KEY, mItem.origin_comment.toString());
                mContext.startActivity(intent);
                break;
            case R.id.container:
                intent = new Intent(mContext, CommentActivity.class);
                intent.putExtra(Constants.ARTICLE_ID_KEY, mItem.origin_comment.aid);
                mContext.startActivity(intent);

                break;
        }
    }

}
